<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>log</title>
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_3423448_ew9ko25kdbr.css">
    <link rel="stylesheet" href="http:////at.alicdn.com/t/font_3423448_ioymlf2fh4r.css">
    <link rel="stylesheet" href="../css/retset.css">
    <link rel="stylesheet" href="../css/log.css">
    <style>
        .btn:disabled {
                        width: 400px;
                        line-height: 50px;
                        background-color: #faab81;
                        border: 1px solid #ff5c00;
                        box-shadow: 0 20px 50px 0 hsl(0deg 0% 64% / 10%);

                    }
    </style>
</head>

<body>
    <!-- 最外边的大盒子 -->
    <div class="main">
        <!-- 左侧盒子 -->
        <div class="left" style="background-image: url(https://cdn.web-global.fds.api.mi-img.com/mcfe--mi-account/static/static/media/banner.5b1efcd8.jpg);background-size: cover;
        background-position: 50%;">&quot;&quot;
        </div>
        <!-- 右侧盒子 -->
        <div class="right">
            <!-- 头部 -->
            <div class="top" style="padding: 20px; height: 60px;">
                <!-- 左边logo -->
                <div class="title_left">
                    <span style="width: 20%;"><i class="iconfont icon-icon-xiaomiguishu"
                            style="color: rgb(255, 105, 0);font-size: 30px;"></i>小米账号</span>
                </div>
                <!-- 右边功能 -->
                <ul class="title_right">
                    <li><a href="">用户协议</a></li>
                    <li><a href="">隐私政策</a></li>
                    <li><a href="">帮助中心</a></li>
                    <li><a href="">中文（简体）</a></li>
                </ul>
            </div>

            <div class="middle">
                <div class="middle_1">
                    <div class="title" style="box-shadow: 0 20px 50px 0 hsl(0deg 0% 64% / 10%);">
                        <h3><span style="width: 60px;color:gray;">注册</span>&emsp;<span style=" width: 60px;">登录</span>
                        </h3>
                        <div class="contner">
                            <!-- 用户要求：名字只能包含数字、字母，数字不可以开头，长度不低于6，不长于12 [0-9 a-z A-Z] -->
                            <p>
                                <label for="user">用&emsp;户&emsp;名</label>
                                <input type="text" class="username">
                                <span class="user_span"></span>
                            </p>
                            <!-- 密码6-12位 不能包含特殊字符  -->
                            <p>
                                <label for="pwd">密&emsp;&emsp;&emsp;码</label>
                                <input type="password" class="password" name="pwd">
                                <span class="pwd_span"></span>
                            </p>


                            <p style="color:gray;margin-bottom: 10px;margin-top: 10px;"><input type="checkbox"
                                    style="font-size: 25px;">已阅读并同意小米账号<a
                                    href="https://static.account.xiaomi.com/html/agreement/user/zh_CN.html">用户协议</a>和<a
                                    href="https://privacy.mi.com/miaccount/zh_CN/">隐私政策</a></p>


                            <button class="btn" disabled style="font-size: 20px; color:aliceblue;">登录</button>

                            <p class="phone"><a href="" style="color: #ff6700;
                            width: 80px; float: left;
                               
                                margin-top: 20px;">忘记密码</a></p>
                            <span class="phone"
                                style="color:#ff6700; display: inline-block; float: right;margin-top: 20px; margin-right: 100px;">
                                <a href="">手机号登录</a>
                            </span>
                            <p style="text-align: center;margin-top:50px;width: 400px;">其他方式登录</p>
                            <p
                                style="width:400px;height: 50px;text-align: center;margin-top: 30px;letter-spacing: 10px;">
                                <i class="iconfont icon-zhifubao" style="font-size: 40px; color: #06b4fd;"></i>
                                <i class="iconfont icon-weixin" style="font-size: 40px;color: #28c445;"></i>
                                <i class="iconfont icon-shejiaotubiao-39" style="font-size: 45px; color: #68a5e1;"></i>
                                <i class="iconfont icon-weibo" style="font-size: 40px; color: #ea5d5c;"></i>
                            </p>
                        </div>


                    </div>
                </div>

            </div>
        </div>
    </div>
    <script src="../js/tools.js"></script>
    <script src="../js/reg.js"></script>
    <script>

        // 验证是否成功   用户名和密码
        let flag1 = false, flag2 = false;

        $('.username').oninput = function () {
            const username = $('.username').value;
            if (username === '') {
                $('.user_span').innerHTML = '不能为空';
                $('.user_span').style.color = 'orange';
                flag1 = false;
                $('.btn').disabled = true;
                return
            }


            flag1 = true;
            if (flag1 && flag2) {
                $('.btn').disabled = false;
                $('.user_span').innerHTML = '';
            }

        }

        $('.password').oninput = function () {
            const password = $('.password').value;
            if (password === '') {
                $('.pwd_span').innerHTML = '不能为空';
                $('.pwd_span').style.color = 'orange';
                flag2 = false;
                $('.btn').disabled = true;
            } else {
                flag2 = true;
            }

            flag2 = true;
            if (flag1 && flag2) {
                $('.btn').disabled = false;
                $('.pwd_span').innerHTML = '';
            }
        }





        $('.btn').onclick = function () {
            // alert('登录成功')
            const username = $('.username').value;
            const password = $('.password').value;
            ajax({
                type: 'post',
                path: '../php/login.php',
                data: {
                    username,
                    password
                },
                success: res => {
                    console.log(res);
                    if (res.status) {
                        localStorage.setItem('login_user', username);
                        // location.href = '04list.html' ;
                        // 获取地址栏信息，判断次登陆页面是从哪里跳转过来的
                        const url = location;
                        const res = url.search;
                        console.log(res);
                        if (res) {
                            const newURL = res.replace('?historyURL=', '');
                            console.log(newURL);
                            location.href = newURL;
                        } else {
                            setCookie('login_user' , username) ;
                            location.href = 'list.html';
                        }
                    } else {
                        alert(res.msg);
                    }
                }
            })
        }
    </script>
</body>

</html>